<template>
  <div class="con">
    <el-container>
      <!-- <el-header style="padding:0;height: 56px;">
        <headbox ref="mychild"></headbox>
      </el-header>
      <el-container>
        <el-aside  style="width:200px;background-color:#393D49;">
          <left></left>
        </el-aside>
      <el-container> -->
    <el-main style="padding:0;">
    <!-- 充值提现 -->
    <div class="contbox6_10">
      <p class="titlelist6_10">
        系统设置
        <span style="color: #999;">&nbsp;&nbsp;/&nbsp;&nbsp;</span>权限管理
      </p>
      <div class="content">
      <div class="sousuojg6_10">
        <el-form :model="formInline" class="demo-form-inline" style="margin-left:20px">
          <el-form-item label="权限名称" class="status" style="width:300px">
            <el-input v-model="formInline.name" class="inName" placeholder="请输入权限名称"></el-input>
          </el-form-item>
          <el-form-item label="权限标识" class="status" style="width:300px">
            <el-input v-model="formInline.permission" placeholder="请输入权限标识"></el-input>
          </el-form-item>
          <el-form-item label="是否菜单" class="status" style="width:300px">
            <el-select v-model="formInline.isShow" clearable placeholder="请选择">
              <el-option label="全部" value=""></el-option>
              <el-option label="是" value="0"></el-option>
              <el-option label="否" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="buttons"> 
        <el-button v-if="isAuth('permissionsSearch')" type="primary" @click="queryPayActiveLists" style="margin-right:10px">搜索</el-button>
        <el-button v-if="isAuth('permissionsReset')" @click="result" >重置</el-button>
      </div>
      <el-table
        :data="tableData"
        :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
          stripe
          border
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '0px' }"
          v-loading="listLoading"
          :fit="true"
      >
        <el-table-column show-overflow-tooltip prop="name" min-width="120" label="权限名称"></el-table-column>
        <!-- <el-table-column show-overflow-tooltip prop="permission" min-width="120" label="权限标识"></el-table-column> -->
        <el-table-column show-overflow-tooltip min-width="100" label="是否菜单">
          <template slot-scope="scope">
            <span v-if='scope.row.isShow == "0"'>是</span>
            <span v-if='scope.row.isShow == "1"'>否</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="sort" min-width="80" label="排序"></el-table-column>
        <!-- <el-table-column show-overflow-tooltip prop="href" min-width="120" label="链接"></el-table-column> -->
        <!-- <el-table-column prop="icon" min-width="100" label="图标"></el-table-column> -->
        <!-- <el-table-column fixed="right" min-width="100" label="状态">
          <template slot-scope="scope">
            <span v-if='scope.row.status == 0'>启用</span>
            <span v-if='scope.row.status == 1'>停用</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column min-width="220" label="操作">
          <template slot-scope="scope">
            <el-button type="text" v-if="isAuth('jurisdictionEditor')" @click="add(2, scope.row.id)">编辑</el-button>
            <!-- <el-button type="primary" v-if='scope.row.status == "1"' @click="updateStatus(scope.row.id,0)" size="mini">启用</el-button>
            <el-button type="danger" v-if='scope.row.status == "0"' @click="updateStatus(scope.row.id,1)" size="mini">停用</el-button> 
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination
        background
        style="text-align: right;"
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="formInline.page"
        :page-size="formInline.number"
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[20, 50, 100]"
        :total="totalNum"
      ></el-pagination>
    </div></div>
    </el-main>

     <!-- 添加/编辑 -->
    <addPermissions :addPermissionsShow="addPermissionsShow" :addPermissionsId='addPermissionsId' :addPermissionsType='addPermissionsType' v-on="addPermissionsSuccess()"></addPermissions>

    <!-- <el-footer style="padding:0;">
      <footerbox></footerbox>
    </el-footer> -->
    </el-container>
    <!-- </el-container>
    </el-container> -->
  </div>
</template>
<script type="text/ecmascript-6">
import bus from '../../assets/js/bus'
import https from '../../plugins/https'
import addPermissions from './addPermissions'
// import InventoryRecords from './InventoryRecords'
import qs from 'qs'
export default {
  data() {
    return {
      formInline: {
        page: 1,
        number: 20,
        name: '',
        permission: '',
        isShow: '',
        // oemUid: localStorage.getItem('jurisdiction') == 0 ? localStorage.getItem('uid') : '',
        // officeUid: localStorage.getItem('jurisdiction') == 2 ? localStorage.getItem('uid') : '',
      },
      dataTime: [],
      totalNum: 0, //总页数
      form: {},
      tableData: [],
      addPermissionsShow: false,
      addPermissionsType: 0,
      listLoading: false,
      from: false,
      addPermissionsId: 0
    };
  },
  components: {
    addPermissions,
    // InventoryRecords
  },
  mounted () {
    this.queryPayActiveList()
  },
  methods: {

    result(){
      this.formInline.name = ""
      this.formInline.permission = ""
      this.formInline.page=1
      this.queryPayActiveList()
    },


    saveUpdateRole (id,useable) {
      useable = (useable == '0' ? '1' : '0')
      this.listLoading = true
      let pl = {
        id: id,
        useable: useable
      }
      https.saveUpdateRole(pl).then(res => {
        if (res.data.code !== '0000') {
          layer.open({
            content: res.data.msg,
            skin: "msg",
            time:  2 //1秒后自动关闭
          });
          // this.$notify({title: "错误",message: res.data.msg,type: "error"});
          this.listLoading = false
          return
        }layer.open({
            content: res.data.msg,
            skin: "msg",
            time:  2 //1秒后自动关闭
          });
        // this.$notify({title: "成功",message: res.data.msg,type: "success"});
        this.queryPayActiveList()
        this.listLoading = false
      })
    },
    // 编辑
    add (type, id) {
      this.addPermissionsType = type
      this.addPermissionsShow = true
      type == 2 && (this.addPermissionsId = id)
    },
    // 角色分配
    queryPayActiveList () {
      this.listLoading = true
      if (this.from == true) {
        return
      }
      this.from = true
      https.querySysMenulist(this.formInline).then(res => {
        if (res.data.code !== '0000') {
          layer.open({
            content: res.data.msg,
            skin: "msg",
            time:  2 //1秒后自动关闭
          });
          // this.$notify({title: "错误",message: res.data.msg,type: "error"});
          this.listLoading = false
          this.from = false
          return
        }
        this.tableData = res.data.data
        this.totalNum = res.data.total
        this.from = false
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.formInline.page = 1; //动态改变
      this.formInline.number = val; //动态改变
      this.queryPayActiveList()
    },
    handleCurrentChange(val) {
      this.formInline.page = val; //动态改变
      this.queryPayActiveList()
    },
    queryPayActiveLists(){
      this.formInline.page = 1; //动态改变
      this.queryPayActiveList()
    },
    //编辑/添加 
    addPermissionsSuccess() {
      bus.$on("addPermissionsSuccess", res => {
        this.addPermissionsShow = res.show;
        if (res.type == 1) {
          this.queryPayActiveList()
        }
      });
    },
  }
};
</script>
<style scoped>
.elbtn{
  float: right;
  margin: 20px;
}
.img {
  display: block;
  width: 100%;
}
.money p {
  width: 100%;
  line-height: 30px;
}
.status {
  font-size: 14px;
  margin-bottom: 20px;
}
.color {
  color: #e6a23c;
}
.mt20 {
  margin-top: 20px;
}
.shopList {
  width: 100%;
  border-bottom: 1px solid #ccc;
  line-height: 80px;
  font-size: 16px;
}
.formItem {
  float: left;
}
.pagination {
  margin-top: 10px;
}
.btnExport {
  float: left;
  margin-top: 10px;
  margin-bottom: 10px;
}
.btn {
  float: right;
}
.titlelist6_10 {
  width: 100%;
  float: left;
  font-size: 16px;
  color: #222;
  margin-top: 40px;
}
.con {
  position: relative;
}

.contbox6_10 {
  width: 100%;
  /*  height: 87.5vh; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.buttons > .el-button{
  width: 100px;
  height: 32px;
  float: left;
}
.sousuojg6_10{
  width: 100%
}
</style>
